home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 March / macformat-022.iso / Shareware City / Developers / MW MPW Binaries 1.1.1a2 / mwcPPC / MWCIncludes / strstream < prev    next >
Encoding:
Text File  |  1994-07-18  |  3.0 KB  |  114 lines  |  [TEXT/MMCC]

  1. // strstream standard header
  2. #ifndef _STRSTREAM_
  3. #define _STRSTREAM_
  4. #include <istream>
  5. #include <ostream>
  6.  
  7. #if __MWERKS__
  8. #pragma options align=mac68k
  9. #endif
  10.  
  11.         // constants
  12. const int _ALSIZE = 512;    // default allocation size
  13. const int _MINSIZE = 32;    // minimum allocation size
  14.         // class strstreambuf
  15. class strstreambuf : public streambuf {
  16. public:
  17.     enum __Strstate {_Allocated = 1, _Constant = 2,
  18.         _Dynamic = 4, _Frozen = 8, _Noread = 16,
  19.         _Strzero = 0};
  20.     _BITMASK(__Strstate, _Strstate);
  21.     strstreambuf(int _N = 0)
  22.         {_Init(_N); }
  23.     strstreambuf(void *(*_A)(size_t), void (*_F)(void *))
  24.         {_Init(), _Palloc = _A, _Pfree = _F; }
  25.     strstreambuf(char *_G, int _N, char *_P = 0,
  26.         _Strstate _S = _Strzero)
  27.         {_Init(_N, _G, _P, _S); }
  28.     strstreambuf(unsigned char *_G, int _N,
  29.         unsigned char *_P = 0)
  30.         {_Init(_N, (char *)_G, (char *)_P); }
  31.     strstreambuf(const char *_G, int _N)
  32.         {_Init(_N, (char *)_G, 0, _Constant); }
  33.     strstreambuf(const unsigned char *_G, int _N)
  34.         {_Init(_N, (char *)_G, 0, _Constant); }
  35.     virtual ~strstreambuf();
  36.     void freeze(int = 1);
  37.     char *str()
  38.         {freeze(); return (gptr()); }
  39.     int pcount() const
  40.         {return (pptr() == 0 ? 0 : pptr() - pbase()); } 
  41. #if _SIGNED_CHAR_IS_DISTINCT
  42.     strstreambuf(signed char *_G, int _N, signed char *_P = 0)
  43.         {_Init(_N, (char *)_G, (char *)_P); }
  44.     strstreambuf(const signed char *_G, int _N)
  45.         {_Init(_N, (char *)_G, 0, _Constant); }
  46. #endif /* _SIGNED_CHAR_IS_DISTINCT */
  47. protected:
  48.     virtual int overflow(int = EOF);
  49.     virtual int pbackfail(int = EOF);
  50.     virtual int underflow();
  51.     virtual streampos seekoff(streamoff, ios::seekdir,
  52.         ios::openmode = ios::in | ios::out);
  53.     virtual streampos seekpos(streampos,
  54.         ios::openmode = ios::in | ios::out);
  55.     void _Init(int = 0, char * = 0, char * = 0,
  56.         _Strstate = _Strzero);
  57.     void _Tidy();
  58.     _Strstate _Strmode;
  59. private:
  60.     char *_Pendsave, *_Seekhigh;
  61.     int _Alsize;
  62.     void *(*_Palloc)(size_t);
  63.     void (*_Pfree)(void *);
  64.     };
  65.         // class istrstream
  66. class istrstream : public istream {
  67. public:
  68.     istrstream(const char *_S)
  69.         : ios(&_Sb), istream(&_Sb), _Sb(_S, 0) {}
  70.     istrstream(const char *_S, int _N)
  71.         : ios(&_Sb), istream(&_Sb), _Sb(_S, _N) {}
  72.     istrstream(char *_S)
  73.         : ios(&_Sb), istream(&_Sb), _Sb((const char *)_S, 0) {}
  74.     istrstream(char *_S, int _N)
  75.         : ios(&_Sb), istream(&_Sb), _Sb((const char *)_S, _N) {}
  76.     virtual ~istrstream();
  77.     strstreambuf *rdbuf() const
  78.         {return ((strstreambuf *)&_Sb); }
  79.     char *str()
  80.         {return (_Sb.str()); }
  81. private:
  82.     strstreambuf _Sb;
  83.     };
  84.         // class ostrstream
  85. class ostrstream : public ostream {
  86. public:
  87.     ostrstream()
  88.         : ios(&_Sb), ostream(&_Sb), _Sb() {}
  89.     ostrstream(char *, int, openmode = out);
  90.     virtual ~ostrstream();
  91.     strstreambuf *rdbuf() const
  92.         {return ((strstreambuf *)&_Sb); }
  93.     void freeze(int _F = 1)
  94.         {_Sb.freeze(_F); }
  95.     char *str()
  96.         {return (_Sb.str()); }
  97.     int pcount() const
  98.         {return (_Sb.pcount()); }
  99. private:
  100.     strstreambuf _Sb;
  101.     };
  102.  
  103. #if __MWERKS__
  104. #pragma options align=reset
  105. #endif
  106.  
  107. #endif
  108.  
  109. /*
  110.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  111.  * Consult your license regarding permissions and restrictions.
  112.  */
  113.  
  114.